<?php 
/**
 * Enter description here...
 * STATUS_DISABLE 0 
 * STATUS_ABLE 1 
 */
 class Dir extends  CActiveRecord{
 	
 public static function model($className=__CLASS__)
	{
		
		return parent::model($className);
	
	}
	 
	
	public function tableName()
	{
		
		return '{{directory}}';
	
	}
 	
 	public function rules()
	{
		return array(
			array('name', 'required','message'=>'不能为空'),
			array('code','safe'),
// 		    array('images', 'file', 'types'=>'jpg, gif, png'),
			
		);
	}
	
	
	
 	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'name' => 'Name',
		    'unid' => 'Unid',
		    'code' => 'Code',	     
		);
	}

	
  public function getAllList(){
  	
  	$data=array();
  	$ret=$this->findAll();
  	if($ret){
  	foreach ($ret as $v) {
  		$data[$v->id]['id']=$v->id;
  		$data[$v->id]['name']=$v->name;
  	}		
  	
  	 }
  	
  	return $data;
  }

  public  function getOptionType(){
  	
  	$data=array();
  	$ret=$this->findAll();
  	if($ret){
  	foreach ($ret as $v) {
  		$data[$v->id]=$v->name;
  	  }		
  	
    }
  	return $data;
  	
  }
  
  
 public function delDir($id){
 	if(is_array($id)){
 		
 		foreach ($id as $v) {	
 		$this->deleteByPk($v);
 		Upload::model()->delFileByDir($v);
 		}
 		
 	}else {

 		$this->deleteByPk($id);
 		Upload::model()->delFileByDir($id);
 	}
 	
 	
 	return TRUE;
 	
 }
  
  
 protected function beforeSave()
	{
		if(parent::beforeSave())
		{
			if($this->isNewRecord)
			{
				$this->code=time();
			}
			return true;
		}
		else
			return false;
	}
}
?>
